package com.wmh.baseservice.merchant.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wmh.baseservice.common.utils.CommUtil;
import com.wmh.baseservice.common.utils.SignDecodeUtil;
import com.wmh.baseservice.common.utils.encrypt.RSAUtil;
import com.wmh.baseservice.common.utils.returnbody.Code;
import com.wmh.baseservice.common.utils.returnbody.ResultCodeInfo;
import com.wmh.baseservice.common.utils.returnbody.ReturnBody;
import com.wmh.baseservice.common.websocket.controller.ChatController;
import com.wmh.baseservice.merchant.pojo.MerchantInfo;
import com.wmh.baseservice.merchant.service.MerchantInfoService;
import com.wmh.baseservice.system.pojo.SysLocation;
import com.wmh.baseservice.system.service.SysLocationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags = "商家-公开接口")
@RestController
@RequestMapping("merchant/public")
public class MerchantPublicController {

    @Resource
    private MerchantInfoService merchantInfoService;


    @ApiOperation("登录验证")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataTypeClass = String.class, name = "account", value = "账号", required = true, example = "PtivnlNFS8UOjbkUyQ6G6n49+c9xIT8npUwsEPpzBNFm0Pt/BVeZkrY6JSf8Rx71ks359U+0Q8d7Iob/P6G9TvWgq0c0SroSzOpsJy6+E7C4Yl12VoorHNE6EImdmPrEdxiEv0ac7HruYP4Nk+D9BIxpf2T0UgDQduFrOkNRWBo="),
            @ApiImplicitParam(paramType = "query", dataTypeClass = String.class, name = "password", value = "密码", required = true, example = "DLUsX3SZ0otbA5J+XE4VrG9K3f2SiLWnyHvSYrQ5CFAkJoFg0AbHKbZnJJsOmSyWwezQvQRWpnYldXmfTrsCFLCPM1RbSgB97f4Wsg0W94+URsPGRLCzRjQlZaGze/uy/DT996rgAskjGh2/1Vy8NE1NGcoE7XjWW+W+JjIGckc="),
            @ApiImplicitParam(paramType = "query", dataTypeClass = String.class, name = "verifyCode", value = "图片验证码", required = true, example = "1234"),
            @ApiImplicitParam(paramType = "query", dataTypeClass = String.class, name = "verifySign", value = "图片验证码密钥", required = true, example = "bOENDfoXAhyXyi8wZ/FsfQxWso6hhErukzPz+s3xQq4=")
    })
    @PostMapping("authority")
    public String authority(String account, String password, String verifyCode, String verifySign) throws Exception {
        password = RSAUtil.decryptByPrivateKey(password);
        account = RSAUtil.decryptByPrivateKey(account);
        //验证码验证
        JSONObject verifyResult = SignDecodeUtil.codeMatches(verifyCode, verifySign, 1000000);
        if (!verifyResult.getBoolean("isSuccess")) {
            return ReturnBody.error(Code.IMAGE_CODE_ERROR, verifyResult.getString("errorMessage"));
        }
        return merchantInfoService.authority(account, password);
    }

    @ApiOperation("testSend")
    @PostMapping("testSend")
    @ApiImplicitParams({
             @ApiImplicitParam(paramType = "query", dataTypeClass = Long.class, name = "id", value = "id", required = false),
     })
    public String testSend(String msg){
        return ReturnBody.success();
    }



}
